/***************************singletondownloader.cpp**********************/
/*****************************************************************************/
/*******************Browsers Daily Build Updater************************/
/************Copyright (C) 2010-2011  Gianluigi Biancucci*************/
/*****************************************************************************/
/*****This is free software, and you are welcome to redistribute it****/
/*****and / or modify underthe terms of GPLV2 License.**************/
/*****This program comes with ABSOLUTELY NO WARRANTY*****/
/*****************************************************************************/

#include "singletondownloader.h"
#include <iostream>
#include <QVariant>
#include <QBuffer>
#include <QNetworkReply>
#include <QNetworkProxy>




SingletonDownloader::SingletonDownloader()
{

    proxy.setType(QNetworkProxy::HttpProxy);
    QObject::connect(this, SIGNAL(finished(QNetworkReply*)),this, SLOT(finished(QNetworkReply*)));

}

SingletonDownloader*  SingletonDownloader::_instance = 0;


SingletonDownloader* SingletonDownloader::getInstance()
{
    if (_instance == 0) {
        _instance = new SingletonDownloader;
    }
    return _instance;
}


bool SingletonDownloader::syncGet(QString url, QByteArray *BA){
    QNetworkReply *reply = this->get(QNetworkRequest(QUrl(url)));
    loop.exec();
    if(reply->error()==0){
        *BA = reply->readAll();
        return true;
    } else return false;
}



void SingletonDownloader::proxySet (QString pr, unsigned int po){
    proxy.setHostName(pr);
    proxy.setPort(po);
    this->setProxy(proxy);

}


void SingletonDownloader::proxyRemove (){

    this->setProxy(QNetworkProxy::NoProxy);

}



void SingletonDownloader::finished(QNetworkReply * reply){
    loop.exit();
    return;

}


